package com.levi.mall.controller;

import com.github.pagehelper.PageInfo;
import com.levi.mall.service.ProductService;
import com.levi.vo.ProductDetailVo;
import com.levi.vo.ProductVo;
import com.levi.vo.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Response;
import java.util.List;

/**
 * @author shentong
 * @since 2022/3/29 11:05 PM
 */
@Api(tags = "商品接口")
@RestController
@RequestMapping("/products")
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping
    @ApiOperation("根据商品分类ID查询下面所有的商品")
    public ResponseVo<PageInfo<ProductVo>> getList(@ApiParam("商品分类id") @RequestParam(required = false) Integer categoryId,
                                        @ApiParam("开始页") @RequestParam(defaultValue = "1") Integer pageNum,
                                        @ApiParam("每页条数") @RequestParam(defaultValue = "10") Integer pageSize) {
        return productService.getList(categoryId, pageNum, pageSize);
    }

    @GetMapping("/{productId}")
    @ApiOperation("查看商品详情")
    public ResponseVo<ProductDetailVo> getInfo(@PathVariable("productId") Integer productId) {
        return productService.getInfo(productId);
    }

    @GetMapping("/all")
    public ResponseVo<PageInfo<ProductVo>> getAllProduct(
            @ApiParam("开始页") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页条数") @RequestParam(defaultValue = "6") Integer pageSize) {
        return productService.allProducts(pageNum, pageSize);
    }
}
